using System;
using System.Collections.Generic;

using OpenTK.Graphics.OpenGL;

namespace ColladaDotNet.OpenTKMapping
{
	
	public class Mesh : Geometry
	{
		public Mesh()
		{
		}
	
		public IList<MeshItem> Items
		{
			get
			{
				return items;
			}
		}

		public Source VerticesPositions
		{
			get
			{
				return vertexPosition;
			}
		}

		internal override void Load(geometry geometry)
		{
			base.Load(geometry);
			Load((mesh)geometry.Item);
		}

		private List<MeshItem> items = new List<MeshItem>();
		public void Load(mesh data)
		{
			foreach (var item in data.Items)
			{
				Items.Add(Document.CreateElement<MeshItem>(item));
			}
			foreach (var local in data.vertices.input)
			{
				LocalInput element = Document.CreateElement<LocalInput>(local);
				vertexInputs.Add(element);
				if (element.Semantic == "POSITION")
					vertexPosition = element.Source;
			}

		}

		private List<LocalInput> vertexInputs = new List<LocalInput>();
		Source vertexPosition;
		public override void Render(BindMaterial material)
		{
			foreach (var item in Items)
			{
				var m=material.Bind(item.Material);
				item.Render();
				if (m != null)
				m.Unbind();
			}
		

		}
	}
}